<template>
  <div class="newsInfo-container">
    <!-- 大标题 -->
    <h3 class="title">{{newInfoList.title}}</h3>
    <!-- 子标题 -->
    <p class="subtitle">
      <span>发表时间:{{newInfoList.add_time | dateFormat}}</span>
      <span>点击:{{newInfoList.click}}次</span>
    </p>
    <!-- 内容区域 -->
    <div class="context" v-html="newInfoList.content"></div>

    <!-- 评论子组件 -->
    <Comments :id="this.id"></Comments>
  </div>
</template>
 
<script>
//导入评论子组件
import Comments from "../subcomponents/comment";
export default {
  name: "",
  data() {
    return {
      id: this.$route.params.id,//将ur地址传过来的id,挂载到data上,方便以后调用
      newInfoList: [],
    };
  },
  mounted() {
    this.getNewsInfo();
  },
  components: {
    //注册子组件
    Comments
  },

  methods: {
    getNewsInfo() {
      this.$http.get("api/getnew/" + this.id)
      .then(res => {
        if (res.body.status === 0) {
          //    console.log(res.body.message[0]);
          this.newInfoList = res.body.message[0];
        }
      });
    },
  },
};
</script>
 
<style  lang = "scss">
.newsInfo-container {
  padding: 0 4px;
  .title {
    font-size: 16px;
    text-align: center;
    color: red;
    margin: 15px 0;
  }
  .subtitle {
    padding: 0 10px;
    font-size: 13px;
    color: #226aff;
    display: flex;
    justify-content: space-between;
  }
  .context {
    img {
      width: 100%;
    }
    padding: 0 10px;
  }
}
</style>